#include"stationary_solver.h"

StationarySolver::StationarySolver(GroundData* GroundData_, PipeData* PipeData_) {
  this->GroundData_ = GroundData_;
  this->PipeData_ = PipeData_;
  T_new = new float*[GroundData_->cell_q_x];
  for(int i=0; i<GroundData_->cell_q_x; i++)
    T_new[i] = new float[GroundData_->cell_q_y];  
  return;
}

int StationarySolver::SetGroundInitialConditions(float T_0, float T_0_surface, float T_0_earth) {
  this->T_0_earth = T_0_earth;
  this->T_0_surface = T_0_surface;
  for(int i=0; i<GroundData_->cell_q_x; i++) {
    for(int j=0; j<GroundData_->cell_q_y; j++) {
      GroundData_->T[i][j] = T_0;
      if(j == 0)
        GroundData_->T[i][j] = T_0_surface;
    }
  }
  return 1;
}

int StationarySolver::SetPipeInitialConditions(float T_in, float T_out) {
  for(int i=0; i<PipeData_->cell_q_y; i++) {
    PipeData_->T_outside[i] = T_in + i*(T_out-T_in)/(2.0f*PipeData_->cell_q_y);
  }
  for(int i=0; i<PipeData_->cell_q_y; i++) {
    PipeData_->T_inside[PipeData_->cell_q_y - i] = T_in + (i+PipeData_->cell_q_y)*(T_out-T_in)/(2.0f*PipeData_->cell_q_y);
  }
  return 1;
}